Skip to content

perf: skip write mutex for PostgreSQL backend#130

Merged
coji merged 1 commit intomainfrom
fix/pg-mutex-bypass
Mar 16, 2026
Merged

perf: skip write mutex for PostgreSQL backend#130
coji merged 1 commit intomainfrom
fix/pg-mutex-bypass

Conversation

@coji
Copy link
Owner

@coji coji commented Mar 16, 2026

Summary

The write mutex that serializes all mutating operations was unconditionally applied to all backends, including PostgreSQL. This defeated PostgreSQL's native concurrent write capabilities (MVCC, advisory locks, FOR UPDATE SKIP LOCKED).

Now the mutex is only applied when backend !== 'postgres'.

Why this is safe

  • SQLite/libsql: Needs the mutex. libsql opens separate connections for transactions, causing SQLITE_BUSY conflicts without serialization.
  • PostgreSQL: Doesn't need it. Concurrent transactions are handled by the database itself. The claimNext implementation already uses FOR UPDATE SKIP LOCKED + pg_advisory_xact_lock for safe concurrent claiming.

Test results

  • SQLite tests: 161 passed (mutex still active)
  • PostgreSQL tests: 11 passed (mutex bypassed)
  • Browser tests: all passed

Closes #123

🤖 Generated with Claude Code

PostgreSQL handles concurrent writes natively via MVCC, advisory locks,
and FOR UPDATE SKIP LOCKED. The single-process write mutex was only
needed for SQLite/libsql (which opens separate connections for
transactions, causing SQLITE_BUSY conflicts).

Now the mutex is conditionally applied only when backend !== 'postgres',
unlocking true concurrent write throughput for PostgreSQL deployments.

Closes #123

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link

vercel bot commented Mar 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
durably-demo Ready Ready Preview Mar 16, 2026 11:51am
durably-demo-vercel-turso Ready Ready Preview Mar 16, 2026 11:51am

@coderabbitai
Copy link

coderabbitai bot commented Mar 16, 2026

Warning

Rate limit exceeded

@coji has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 13 minutes and 11 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f1ee6ede-2f28-4e92-a69e-eb355fa94321

📥 Commits

Reviewing files that changed from the base of the PR and between 6645766 and a0eb561.

📒 Files selected for processing (1)
  • packages/durably/src/storage.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/pg-mutex-bypass
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coji coji merged commit 938c925 into main Mar 16, 2026
5 checks passed
@coji coji deleted the fix/pg-mutex-bypass branch March 16, 2026 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: single mutex serializes all writes even on PostgreSQL

1 participant